﻿
app.controller('HiddenTroubleController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;

    $scope.InitPageRole = function (module, action) {

    }

    $scope.ShowToolBox = function (id) {
        mui.toast(id);
    }
	$scope.InitLxUpload = function(id,index,category){
		try{
		lx.media.chooseImage({
			count:1,
			sourceType:["album","camera"],
			quality:'high',
			success:function(res){
				var filelist = res.tempFiles;
				var img = document.getElementById(id+index);
				img.src=filelist[0].base64;
				var file = $scope.base64ToFile(filelist[0].base64,filelist[0].name);
				Upload.upload({
							method: 'POST',
							url: '../HiddenTrouble/UploadFormImage',
							data: { "Category": category },
							file: file
						}).success(function (ret) {
							common.success($scope, null, ret);
							if (ret.Code == 100) {
								 $scope.FileList.push(ret.Data);
							}
							else {
							   mui.toast(ret.Msg);
							}
						})	
			}
		});
		}catch(error){
			mui.toast(error);
		}
	}
	$scope.base64ToFile = function(base64str,filename){
		try{
			const arr = base64str.split(',');
			const mimeType = arr[0].match(/:(.*?);/)[1]; // 获取 MIME 类型
			var byteCharacters = atob(arr[1]);
		  var byteArrays = [];
		  for (var offset = 0; offset < byteCharacters.length; offset += 1024) {
			var slice = byteCharacters.slice(offset, offset + 1024);
			var byteNumbers = new Array(slice.length);
			for (var i = 0; i < slice.length; i++) {
			  byteNumbers[i] = slice.charCodeAt(i);
			}
			var byteArray = new Uint8Array(byteNumbers);
			byteArrays.push(byteArray);
		  }
		  var file = new Blob(byteArrays, { type: mimeType });
		  file.lastModifiedDate = new Date();
		  file.name = filename;
		  return file;
		}catch(error){
			mui.toast(error);
		}						
	}

    $scope.GetNodeMenu = function (node) {
        mui.showLoading("正在加载..", "div");
        var hmenu = sessionStorage.getItem('HTMenu');
        if (hmenu == null) {
            $http({
                method: 'POST',
                url: '../Account/GetMMenuList',
                data: { 'Node': node }
            })
                .success(function (ret) {
                    mui.hideLoading();
                    common.success($scope, null, ret);
                    if (ret.Code == 100) {
                        $scope.CheckMenuList = ret.Data;
                        sessionStorage.setItem("HTMenu", JSON.stringify(ret.Data));
                    }
                    else {
                        mui.toast(ret.Msg);
                    }
                })
                .error(function (data, status, headers, config) {
                    mui.toast("请检查网络");
                });
        }
        else {
            $scope.CheckMenuList = JSON.parse(hmenu);
            mui.hideLoading();
        }
    }


    $scope.InitIndexPageSource = function () {
        $("input.bootstrap-switch").bootstrapSwitch({
            onText: "外部",
            offText: "内部",
            onSwitchChange: function (event, state) {
                if (state == true) {
                    $scope.SourceType = 1;
                } else {
                    $scope.SourceType = 0;
                    $scope.GetMonthView($scope.Data.Year, 'monthview', $scope.SourceType);
                }
                $scope.GetHiddenTroubleCount($scope.SourceType);
                $scope.GetFactoryView($scope.Data.Year, $scope.SourceType);
                $scope.GetTypeView($scope.Data.Year, $scope.SourceType);
                $scope.GetSourceView($scope.Data.Year, $scope.SourceType);

            }
        })
    }
    $scope.InitIndexPage = function (IsManageDep, Year) {
        if (IsManageDep == 1 && $scope.SourceType == 1) {
            $scope.GetDepartmentView(Year);
        }
        else {
            $scope.GetMonthView(Year, 'monthview', $scope.SourceType);
        }
        $scope.GetSourceView(Year, $scope.SourceType);
        $scope.GetFactoryView(Year, $scope.SourceType);
        $scope.GetTypeView(Year, $scope.SourceType);
    }
    $scope.GetHiddenTroubleCount = function (source) {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleCount',
            data: { 'SourceType': source }
        }).success(function (ret) {
            if (ret.Code == 100) {
                $scope.HiddenTroubleCount = ret.Data;
            } else {
                $scope.DataLoading = false;
                alertify.alert(ret.Msg);
            }

        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetTypeTreeList = function (control) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetTypeTreeList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.PageLoading = false;
                if (ret.Code == 100) {
                    $("#" + control).html("");
                    $("#" + control).ProTree({
                        arr: ret.Data,
                        simIcon: "fa fa-file-o",//单个标题字体图标 不传默认glyphicon-file
                        mouIconOpen: "fa fa-folder-open-o",//含多个标题的打开字体图标  不传默认glyphicon-folder-open
                        mouIconClose: "fa fa-folder-o",//含多个标题的关闭的字体图标  不传默认glyphicon-folder-close
                        callback: function (id, name) {
                            $scope.Type.ParentNodeId = id;
                            $("#ParentName").val(name);
                        }
                    })
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetTypeTableList = function (control) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetTypeTreeList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.PageLoading = false;
                if (ret.Code == 100) {
                    $("#" + control).ProTree({
                        arr: ret.Data,
                        simIcon: "fa fa-file-o",//单个标题字体图标 不传默认glyphicon-file
                        mouIconOpen: "fa fa-folder-open-o",//含多个标题的打开字体图标  不传默认glyphicon-folder-open
                        mouIconClose: "fa fa-folder-o",//含多个标题的关闭的字体图标  不传默认glyphicon-folder-close
                        callback: function (id, name) {
                            $scope.GetTypeDetail(id);
                        }
                    })
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
                $scope.PageLoading = false;
            });
    }

    $scope.GetTypeDetail = function (Id) {
        if (Id == null)
            return false;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleTypeDetail',
            data: { "Id": Id }
        }).success(function (ret) {
            if (ret.Code == 100) {
                $scope.TypeDetail = ret.Data;
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.AddHiddenTroubleType = function (model) {
        if (model.ParentNodeId == null || model.ParentNodeId == '') {
            alertify.alert("请选择隐患类型父节点！");
            return false;
        }
        if (model.TypeName == null || model.TypeName == '') {
            alertify.alert("请填写隐患类型名称！");
            return false;
        }
        $scope.PageLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../HiddenTrouble/AddHiddenTroubleType',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.PageLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);

                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.EditHiddenTroubleType = function (model) {
        if (model.TypeName == null || model.TypeName == '') {
            alertify.alert("请填写隐患类型名称！");
            return false;
        }
        $scope.PageLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../HiddenTrouble/EditHiddenTroubleType',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.PageLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        window.location.href = window.location.href;
                    }, 3000);

                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })
    }

    $scope.GetFactoryArea = function () {
        $scope.PageLoading = true;
        $scope.FactoryArea = [];
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetFactoryArea'
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                $scope.FactoryArea = ret.Data;
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }
    $scope.MGetPlaceList = function (id) {
        $scope.PlaceList = [];
        $http({
            method: 'POST',
            url: '../IssueReport/GetParkPlace',
            data: { "ParkId": id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.PlaceList = ret.Data;
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                mui.toast("请检查网络");
            });
    }
    $scope.GetHiddenTroubleLevelList = function () {
        $scope.PageLoading = true;
        $scope.LevelList = [];
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleLevelList'
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                $scope.LevelList = ret.Data;
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }


    $scope.GetSourceList = function (type) {
        $scope.SourceList = [];
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleSourceList',
            data: { 'Type': type }
        }).success(function (ret) {
            if (ret.Code == 100) {
                $scope.SourceList = ret.Data;
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.PageLoad = function () {
        $("#FormLoading").css("display", "block");
        $scope.LoadingMsg = "页面正在加载...";
        setTimeout(function () {
            $("#FormLoading").css("display", "none");
        }, 2000);
    }


    $scope.GetHiddenTroubleType = function () {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleType'
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                $scope.CategoryList = ret.Data;
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetHiddenTroubleTypeChild = function (parent, control) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleType',
            data: { 'ParentNode': parent }
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                $scope.CategoryChildList = ret.Data;
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.BindDepartmentList = function (control, defaultvalue) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetDepartmentList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $.each(ret.Data, function (i, n) {
                        if (n.DepartmentName != "系统支持") {
                            if (defaultvalue != null) {
                                if (n.Id == defaultvalue)
                                    $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                                else
                                    $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                            else {
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                        }
                    })
                    //$("#" + control).selectpicker('refresh');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.BindSourceList = function (control, defaultvalue) {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleSourceList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $.each(ret.Data, function (i, n) {
                        if (defaultvalue != null) {
                            if (n.Id == defaultvalue)
                                $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.Source + "</option>")($scope));
                            else
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.Source + "</option>")($scope));
                        }
                        else {
                            $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.Source + "</option>")($scope));
                        }
                    })
                    $("#" + control).selectpicker('refresh');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.ShowLoader = function (txt) {
        $("#").css("display", "block");
        if (txt == null || txt == "")
            txt = "正在加载";
        $("#").html(txt);
    }

    $scope.HideLoader = function (txt) {
        $("#").css("display", "none");
        $("#").css("display", "block");
    }

    $scope.AddHiddenTroubleForm = function (model, solution, url) {
        if (model.FactoryAreaId == null || model.FactoryAreaId == "") {
            mui.toast("请选择园区.");
            return false;
        }
        if (model.DepartmentId == null || model.DepartmentId == "0") {
            mui.toast("请选择责任部门.");
            return false;
        }
        if (model.ResponsibleEmloyeeNo == null || model.ResponsibleEmloyeeNo == "") {
            mui.toast("请选择责任人.");
            return false;
        }
        if (model.SourceId == null || model.SourceId == "") {
            mui.toast("请选择隐患来源.");
            return false;
        }
        if (model.CategoryAreaId == null || model.CategoryAreaId == "") {
            mui.toast("请选择隐患类型.");
            return false;
        }
        if (model.TypeId == null || model.TypeId == "") {
            mui.toast("请选择隐患子类型.");
            return false;
        }
        if (model.PlaceId == null || model.PlaceId == "") {
            mui.toast("请选择场所.");
            return false;
        }
        if (model.Description == null || model.Description == "") {
            mui.toast("请填写隐患描述.");
            return false;
        }
        if (model.Requirement == null || model.Requirement == "") {
            mui.toast("请填写整改要求.");
            return false;
        }
        model.CheckTime = $("#datetime").val();
        $scope.Submiting = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../HiddenTrouble/AddHiddenTroubleForm',
            data: { 'model': model,'FileList':$scope.FileList }
        })
            .success(function (ret) {
                $scope.Submiting = false;
                if (ret.Code == 100) {
                    mui.toast(ret.Msg);
                    setTimeout(function () {
                        window.location = "../HiddenTrouble/MHiddenTroubleList";
                    }, 2000);
                } else
                    mui.toast(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                mui.toast("请检查网络");
            })
    }

    $scope.AddHiddenTroubleSolution = function (formid, model, pagename, page) {
        $scope.filelist = [];
        var flag = $('#IsTemporary').is(':checked');
        for (var x = 0; x < model.length; x++) {
            if (x == 0) {
                model[x].IsTemporary = flag;
            } else {
                model[x].IsTemporary = false;
            }
            model[x].EmployeeNo = $scope.User.UserNo;
            idname = "SolutionFile_" + x;
            var files = document.getElementById(idname).files;
            if (files.length > 0) {
                for (var i = 0; i < files.length; i++) {
                    var obj = {};
                    obj['SolutionFile_' + x] = files[i];
                    $scope.filelist.push(obj);
                }
            }
            if (model[x].PlanCompleteTime == null) {
                alertify.alert("请填写计划完成日期");
                return false;
            }

        }

        $scope.PageLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        Upload.upload({
            method: 'POST',
            url: '../HiddenTrouble/AddHiddenTroubleSolution',
            data: { 'FormId': formid, 'list': model },
            file: $scope.filelist
        })
            .success(function (ret) {
                $scope.PageLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    if (pagename != null && pagename != "") {
                        setTimeout(function () {
                            location.href = pagename + "?page=" + page
                        }, 3000);
                    }

                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })
    }

    $scope.AddSolutionForm = function (addmodel, formid) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/AddSolution',
            data: { 'FormId': formid, 'model': addmodel, 'FileList': $scope.FileList }
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                mui.toast(ret.Msg);
                setTimeout(function () {
                    location.href = "MHiddenTroubleSolutionList?FormId=" + formid;
                }, 3000);

            } else
                mui.toast(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetTeamListByDepartment = function (departmentId) {
        $scope.PageLoading = true;
        $scope.TeamList = [];
        $http({
            method: 'POST',
            url: '../Organization/GetTeamByDepartment',
            data: { 'DepartmentId': departmentId }
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                $scope.TeamList = ret.Data;
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetEmployeeByDepartment = function (departmentId) {
        $scope.PageLoading = true;
        $scope.EmployeeList = [];
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetEmployeeByDepartment',
            data: { 'DepartmentId': departmentId }
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                $scope.EmployeeList = ret.Data;
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetHiddenTroubleState = function (isshow) {
        $scope.PageLoading = true;
        $scope.StateList = [];
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleState'
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                $scope.StateList = ret.Data;
                $scope.slist = [];
                for (var i = 0; i < $scope.StateList.length; i++) {
                    $scope.slist.push(ret.Data[i].StateName);
                }
                if (isshow) {
                    $scope.MyStep = $("#step");
                    $scope.MyStep.step({
                        index: -1,
                        time: 500,
                        title: $scope.slist
                    });
                }
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.ShowStep = function (type, State) {
        $("#step").html("");
        $scope.MyStep = $("#step");
        if (type == 1) {
            var list = [];
            for (var i = 0; i < $scope.slist.length; i++) {
                if ($scope.slist[i] != '待复查') {
                    list.push($scope.slist[i]);
                }
            }
            $scope.MyStep.step({
                index: -1,
                time: 500,
                title: list
            });
            $scope.MyStep.toStep(State - 1);
        }
        else {
            $scope.MyStep.step({
                index: -1,
                time: 500,
                title: $scope.slist
            });
            $scope.MyStep.toStep(State - 1);
        }
    }
    $scope.SelectPosition = function (entity) {
        entity.X = Math.round($("#h_XAxis").val() * 100);
        entity.Y = Math.round($("#h_YAxis").val() * 100);
    }
    $scope.AddSolutionItem = function () {
        var item = $("div[id^='SolutionItem_']");
        var index = item.length + 1;
        var htmlcontent = '<div id="SolutionItem_' + (index - 1) + '"><div class="form-group"><label class="col-sm-1 control-label">整改措施 ' + index + ' :</label></div>';
        htmlcontent += '<div class="form-group">';
        //htmlcontent += '<select class="form-control" ng-model="SolutionModel[' + (index - 1) + '].StateId"><option value="" ng-selected="true">选择整改状态</option><option ng-repeat="x in StateList" value="{{x.Id}}">{{x.StateName}}</option></select></div>';
        htmlcontent += '<label class="col-sm-1 control-label">计划完成时间：</label><div class="col-sm-2">';
        htmlcontent += '<datepicker id="PlanCompleteTime" option="datetimeOption" format="L" ng-model="SolutionModel[' + (index - 1) + '].PlanCompleteTime"></datepicker></div>';
        htmlcontent += '<label class="col-sm-1 control-label">联系部门：</label><div class="col-sm-2">';
        htmlcontent += '<input type="text" class="form-control" ng-model="SolutionModel[' + (index - 1) + '].DepartmentName" /></div>';
        htmlcontent += '<label class="col-sm-1 control-label">联系人：</label><div class="col-sm-2">';
        htmlcontent += '<input type="text" class="form-control" ng-model="SolutionModel[' + (index - 1) + '].Responsible" /></div></div>';
        htmlcontent += '<div class="form-group"><label class="col-sm-1 control-label">整改措施：</label><div class="col-sm-8">';
        htmlcontent += '<textarea class="form-control autosize" ng-model="SolutionModel[' + (index - 1) + '].SolutionContent" ng-init="SolutionModel[0].SolutionContent=\'\'" style="overflow: hidden; overflow-wrap: break-word; resize: horizontal; height: 80px;"></textarea>';
        htmlcontent += '</div></div><div class="form-group"><label class="col-sm-1 control-label">上传文件:</label><div class="col-lg-8">';
        htmlcontent += '<input type="file" class="form-control" style="border:none;" id="SolutionFile_' + (index - 1) + '" multiple>';
        htmlcontent += '</div></div><div class="form-group"><div class="col-lg-2"></div><div class="col-lg-1"><button class="btn-danger btn" ng-click="DeleteSolutionItem(' + (index - 1) + ');">删除整改措施</button></div></div></div>';
        var $html = $compile(htmlcontent)($scope);
        $("#SolutionItems").append($html);
    }

    $scope.DeleteSolutionItem = function (index) {
        $("#SolutionItem_" + index).remove();
    }


    $scope.GetHiddenTroublePageList = function (model, page) {
        if (page == 1) {
            $scope.HiddenTroubleList = [];
        }
        $scope.PageIndex = page;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroublePageList',
            data: { "model": model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);

                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    for (var i = 0; i < ret.Data.Data.length; i++) {
                        $scope.HiddenTroubleList.push(ret.Data.Data[i]);
                    }
                    if (ret.Data.Data.length == 0) {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                    }
                    else {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.InitHiddenTroubleListPage = function (type) {
        $scope.PageIndex = 1;
        mui.init({
            pullRefresh: {
                container: '#pullrefresh',
                down: {
                    style: 'circle',
                    auto: false,//可选,默认false.首次加载自动上拉刷新一次
                    callback: function () {
                        setTimeout(function () {
                            if (type == 1) {
                                $scope.GetHiddenTroubleUnCompleteList($scope.SearchModel, 1);
                            }
                            else {
                                $scope.GetHiddenTroublePageList($scope.SearchModel, 1);
                            }

                            mui('#pullrefresh').pullRefresh().refresh(true);
                            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                        }, 1500);

                    }
                }, up: {
                    auto: false,
                    contentrefresh: '正在加载...',
                    callback: function () {
                        if (type == 1) {
                            $scope.GetHiddenTroubleUnCompleteList($scope.SearchModel, $scope.PageIndex + 1);
                        }
                        else {
                            $scope.GetHiddenTroublePageList($scope.SearchModel, $scope.PageIndex + 1);
                        }
                    },
                }
            }
        });
    }

    $scope.GetHiddenTroubleUnCompleteList = function (model, page) {
        if (page == 1) {
            $scope.HiddenTroubleList = [];
        }
        $scope.PageIndex = page;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleUnCompleteList',
            data: { "model": model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);

                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    for (var i = 0; i < ret.Data.Data.length; i++) {
                        $scope.HiddenTroubleList.push(ret.Data.Data[i]);
                    }
                    if (ret.Data.Data.length == 0) {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                    }
                    else {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.ShowSolution = function (Id, model, page, pagename, IsAdd, IsEdit, IsDelete) {
        var control = $("#tr_" + Id);
        if ($("#tr_solution_" + Id).length > 0) {
            $("#tr_solution_" + Id).remove();
        }
        else {
            var htmlcontent = "<tr id='tr_solution_" + Id + "'><td colspan='13'>";
            htmlcontent += '<table class="table table-striped table-bordered table-hover">';
            htmlcontent += '<thead><tr style=""><th style="width:2%">序号</th><th style="width:2%">临时措施</th><th style="width:2%">整改情况</th><th style="width:5%">计划完成时间</th><th style="width:5%">责任班组/责任人</th><th style="width:15%">措施描述</th><th style="width:10%">操作</th></tr></thead>';
            htmlcontent += '<tbody>';
            if (model.length > 0) {
                for (var i = 0; i < model.length; i++) {
                    htmlcontent += '<tr>';
                    htmlcontent += '<td>' + (i + 1) + '</td>';
                    if (model[i].IsTemporary) {
                        htmlcontent += '<td>是</td>';
                    }
                    else {
                        htmlcontent += '<td>否</td>';
                    }
                    if (model[i].Process == 100) {
                        htmlcontent += '<td>完成</td>';
                    }
                    else {
                        htmlcontent += '<td>未完成</td>';
                    }

                    htmlcontent += '<td>' + $filter('JSONDate')(model[i].PlanCompleteTime, 'yyyy-MM-dd'); +'</td>';
                    htmlcontent += '<td>' + model[i].EmployeeNo + "-" + model[i].EmployeeName + '</td>';
                    htmlcontent += '<td>' + model[i].SolutionContent + '</td>';
                    htmlcontent += '<td> <a ng-show="' + (model[i].Process < 100) + '" href="SolutionRectificationAdd?SolutionId=' + model[i].SolutionId + '&FormId=' + Id + '&page=' + page + '&pagename=' + pagename + '" class="btn btn-info btn-xs btn-label"><i class="fa fa-wrench"></i>整改</a> <a ng-show="1==1" href="SolutionEdit?SolutionId=' + model[i].SolutionId + '&FormId=' + Id + '&page=' + page + '" class="btn btn-default btn-xs btn-label"><i class="fa fa-pencil"></i>编辑</a> <a ng-show="1==1" ng-click="DeleteSolution(\'' + model[i].SolutionId + '\');" class="btn btn-danger btn-xs btn-label"><i class="fa fa-trash-o"></i>删除</a></td>';
                    htmlcontent += '</tr>';
                }
            }
            else {
                htmlcontent += "<tr><td colspan='7'>暂无解决措施</td></tr>";
            }
            htmlcontent == '</tbody>';
            htmlcontent += '</table></td></tr>';
            var $html = $compile(htmlcontent)($scope);
            control.after($html);
        }
    }

    $scope.ShowCompleteSolution = function (Id, model, page, pagename, IsEdit, IsDelete) {
        var control = $("#tr_" + Id);
        if ($("#tr_solution_" + Id).length > 0) {
            $("#tr_solution_" + Id).remove();
        }
        else {
            var htmlcontent = "<tr id='tr_solution_" + Id + "'><td colspan='13'>";
            htmlcontent += '<table class="table table-striped table-bordered table-hover">';
            htmlcontent += '<thead><tr style=""><th style="width:2%">序号</th><th style="width:2%">临时措施</th><th style="width:2%">整改进度</th><th style="width:5%">计划完成时间</th><th style="width:5%">责任人</th><th style="width:15%">措施描述</th><th style="width:10%">操作</th></tr></thead>';
            htmlcontent += '<tbody>';
            if (model.length > 0) {
                for (var i = 0; i < model.length; i++) {
                    htmlcontent += '<tr>';
                    htmlcontent += '<td>' + (i + 1) + '</td>';
                    if (model[i].IsTemporary) {
                        htmlcontent += '<td>是</td>';
                    }
                    else {
                        htmlcontent += '<td>否</td>';
                    }
                    if (model[i].Process == 100) {
                        htmlcontent += '<td>完成</td>';
                    }
                    else {
                        htmlcontent += '<td>未完成</td>';
                    }
                    htmlcontent += '<td>' + $filter('JSONDate')(model[i].PlanCompleteTime, 'yyyy-MM-dd'); +'</td>';
                    htmlcontent += '<td>' + model[i].EmployeeNo + "-" + model[i].EmployeeName + '</td>';
                    htmlcontent += '<td><span">' + ("" + model[i].SolutionContent) + '</span></td>';
                    htmlcontent += '<td><a ng-show="' + IsEdit + '==1" href="SolutionEdit?SolutionId=' + model[i].SolutionId + '&FormId=' + Id + '&page=' + page + '&pagename=' + pagename + '" class="btn btn-default btn-xs btn-label"><i class="fa fa-pencil"></i>编辑</a> <a ng-show="' + IsDelete + '==1" ng-click="DeleteSolution(\'' + model[i].SolutionId + '\');" class="btn btn-danger btn-xs btn-label"><i class="fa fa-trash-o"></i>删除</a></td>';
                    htmlcontent += '</tr>';
                }
            }
            else {
                htmlcontent += "<tr><td colspan='7'>暂无解决措施</td></tr>";
            }
            htmlcontent == '</tbody>';
            htmlcontent += '</table></td></tr>';
            var $html = $compile(htmlcontent)($scope);
            control.after($html);
        }
    }

    $scope.DeleteHiddenTrouble = function (FormId, SearchModel, page) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.PageLoading = true;
                $http({
                    method: 'POST',
                    url: '../HiddenTrouble/DeleteHiddenTrouble',
                    data: { 'FormId': FormId }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            alertify.alert("删除成功！");
                            $scope.GetHiddenTroublePageList(SearchModel, page);
                        }
                        else {
                            alertify.alert(ret.Msg);
                            $scope.GetHiddenTroublePageList(SearchModel, page);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.PageLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }
    $scope.RemoveHiddenTrouble = function (FormId, SearchModel, page) {
        mui.confirm('确认撤销该问题单？', '系统提醒', ['否', '是'], function (e) {
            if (e.index == 1) {
                $http({
                    method: 'POST',
                    url: '../HiddenTrouble/RemoveHiddenTrouble',
                    data: { 'FormId': FormId }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            mui.toast("撤销成功！");
                            setTimeout(function () {
                                location.href = "../PlaceSafety/MMyPlaceList";
                            }, 3000);
                        }
                        else {
                            mui.toast(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.PageLoading = false;
                    });

            } else {
                //mui.toast("");
            }
        })
    }

    $scope.ShowImage = function (path) {
        $scope.ImagePath = path;
    }

    $scope.GetHiddenTroubleEditDetail = function (Id) {
        if (Id == null)
            return false;
        $scope.DataLoading = true;
        $scope.LoadingMsg = "页面加载中";
        setTimeout(function () {
            $http({
                method: 'POST',
                url: '../HiddenTrouble/GetHiddenTroubleDetail',
                data: { "FormId": Id }
            }).success(function (ret) {
                if (ret.Code == 100) {
                    $scope.HiddenTroubleEditModel = ret.Data;
                    $scope.HiddenTroubleEditModel.CheckTime = $filter('JSONDate')($scope.HiddenTroubleEditModel.CheckTime, 'yyyy-MM-dd HH:mm');
                    $scope.HiddenTroubleEditModel.CreateTime = $filter('JSONDate')($scope.HiddenTroubleEditModel.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                    $scope.HiddenTroubleEditModel.FactoryAreaId = $scope.HiddenTroubleEditModel.FactoryAreaId + "";
                    $scope.HiddenTroubleEditModel.PlaceId = $scope.HiddenTroubleEditModel.PlaceId + "";
                    $scope.HiddenTroubleEditModel.HiddenTroubleCategoryId = $scope.HiddenTroubleEditModel.CategoryId + "";
                    $scope.HiddenTroubleEditModel.TypeId = $scope.HiddenTroubleEditModel.TypeId + "";
                    $scope.HiddenTroubleEditModel.LevelId = $scope.HiddenTroubleEditModel.LevelId + "";
                    $scope.HiddenTroubleEditModel.State = $scope.HiddenTroubleEditModel.State + "";
                    $scope.HiddenTroubleEditModel.CategoryAreaId = $scope.HiddenTroubleEditModel.CategoryAreaId + "";
                    $scope.HiddenTroubleEditModel.SourceId = $scope.HiddenTroubleEditModel.SourceId + "";
                    $scope.GetHiddenTroubleTypeChild($scope.HiddenTroubleEditModel.CategoryId, 'div_typeselect');
                    $scope.BindDepartmentList('Dep_Select', $scope.HiddenTroubleEditModel.DepartmentId);
                    $scope.DataLoading = false;
                    //$scope.GetTeamListByDepartment($scope.HiddenTroubleEditModel.DepartmentId);
                    $scope.GetEmployeeByDepartment($scope.HiddenTroubleEditModel.DepartmentId);
                    $scope.MGetPlaceList($scope.HiddenTroubleEditModel.FactoryAreaId);
                    $scope.RetFileList = [];
                    for (var i = 0; i < ret.Data.SolutionList.length; i++) {
                        var solution = ret.Data.SolutionList[i];
                        for (var j = 0; j < solution.RectificationRecordList.length; j++) {
                            var reti = solution.RectificationRecordList[j];
                            for (var k = 0; k < reti.FileList.length; k++) {
                                $scope.RetFileList.push(reti.FileList[k]);
                            }
                        }
                    }


                } else {
                    $scope.DataLoading = false;
                    alertify.alert(ret.Msg);
                }

            }).error(function (data, status, headers, config) {
                common.error($scope);
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            })
        }, 3000);

    }

    $scope.GetReviewList = function (formId) {
        if (formId == null)
            return false;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetReviewList',
            data: { "FormId": formId }
        }).success(function (ret) {
            if (ret.Code == 100) {
                $scope.ReviewList = ret.Data;
            } else {
                $scope.DataLoading = false;
                mui.toast(ret.Msg);
            }

        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            mui.toast("请检查网络");
        })
    }

    $scope.DeleteHiddenTroubleFile = function (Id, filelist) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../HiddenTrouble/DeleteHiddenTroubleFile',
                    data: { 'Id': Id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            for (var i = 0; i < filelist.length; i++) {
                                if (filelist[i].Id == Id) {
                                    filelist.splice(i, 1);
                                }
                            }
                            alertify.alert("删除成功！");
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.PageLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.EditHiddenTroubleForm = function (formId, model, ischeck, pagename) {
        if (ischeck == "1" || ischeck == "2") {
            model.Valid = true;
            model.State = 1;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../HiddenTrouble/EditHiddenTrouble',
            data: { 'FormId': formId, 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    mui.toast(ret.Msg);
                    location.href = "";
                    if (ischeck == "1") {
                        location.href = "../CheckForm/MDailyCheckFormPageList";
                    }
                    else {
                        location.href = pagename;
                    }
                } else
                    mui.toast(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                mui.toast("请检查网络");
            })
    }

    $scope.DownloadFile = function (fileId) {
        $http({
            method: 'GET',
            url: '../Download/DownloadFile?FileId=' + fileId
        }).success(function (ret) {
            if (ret.Code != null) {
                alertify.alert(ret.Msg);
            }
            else {

            }

        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }


    $scope.DeleteSolution = function (Id, SearchModel, page) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../HiddenTrouble/DeleteSolution',
                    data: { 'Id': Id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            alertify.alert("删除成功！");
                            $scope.GetHiddenTroublePageList(SearchModel, page);
                        }
                        else {
                            alertify.alert(ret.Msg);
                            $scope.GetHiddenTroublePageList(SearchModel, page);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.PageLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.GetSolutionEditDetail = function (Id, pagename) {
        if (Id == null)
            return false;
        $scope.DataLoading = true;
        $scope.LoadingMsg = "页面加载中";
        setTimeout(function () {
            $http({
                method: 'POST',
                url: '../HiddenTrouble/GetSolutionById',
                data: { "SolutionId": Id }
            }).success(function (ret) {
                if (ret.Code == 100) {
                    $scope.SolutionEditModel = ret.Data;
                    $scope.SolutionEditModel.StateId = $scope.SolutionEditModel.StateId + "";
                    if ($scope.SolutionEditModel.Process == null) {
                        $scope.SolutionEditModel.Process = 0;
                    }
                    if ($scope.SolutionEditModel.TeamId != null) {
                        $scope.SolutionEditModel.TeamId = $scope.SolutionEditModel.TeamId + "";
                    }
                    $scope.SolutionEditModel.PlanCompleteTime = $filter('JSONDate')($scope.SolutionEditModel.PlanCompleteTime, 'yyyy-MM-dd');
                    $scope.SolutionEditModel.CreateTime = $filter('JSONDate')($scope.SolutionEditModel.CreateTime, 'yyyy-MM-dd');
                    if (pagename == 'RectificationAdd') {
                        $scope.InitRectifationPage($scope.SolutionEditModel.Process);
                    }
                    $scope.DataLoading = false;
                } else {
                    $scope.DataLoading = false;
                    alertify.alert(ret.Msg);
                }

            }).error(function (data, status, headers, config) {
                common.error($scope);
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            })
        }, 3000);

    }

    $scope.GetSolutionDetail = function (Id, pagename) {
        $scope.SolutionDetail = {};
        if (Id == null)
            return false;
        $scope.DataLoading = true;
        $scope.LoadingMsg = "页面加载中";
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetSolutionDetail',
            data: { "SolutionId": Id }
        }).success(function (ret) {
            if (ret.Code == 100) {
                $scope.SolutionDetail = ret.Data;
            } else {
                $scope.DataLoading = false;
                alertify.alert(ret.Msg);
            }

        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.DeleteSolutionFile = function (Id, filelist) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../HiddenTrouble/DeleteSolutionFile',
                    data: { 'Id': Id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            for (var i = 0; i < filelist.length; i++) {
                                if (filelist[i].Id == Id) {
                                    filelist.splice(i, 1);
                                }
                            }
                            alertify.alert("删除成功！");
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.PageLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.EditSolution = function (Id, model, pagename, page) {
        var files = document.getElementById("SolutionFile").files;
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        Upload.upload({
            method: 'POST',
            url: '../HiddenTrouble/EditSolution',
            data: { 'SolutionId': Id, 'model': model },
            file: files
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = pagename + "?page=" + page
                    }, 3000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })
    }

    $scope.InitRectifationPage = function (val) {
        //$("#slider-range-min-amount").text(val + "%");
        //$scope.AddModel.Process = val;
        //$("#slider-range-min").slider({
        //    range: "min",
        //    value: val,
        //    min: 0,
        //    max: 100,
        //    slide: function (event, ui) {
        //        $("#slider-range-min-amount").text(ui.value + "%");
        //        $scope.AddModel.Process = ui.value;
        //        if (ui.value == 100) {
        //            $scope.AddModel.IsComplete = "true";
        //        }
        //        else {
        //            $scope.AddModel.IsComplete = "false";
        //        }
        //    }
        //});
    }

    $scope.AddRectificationRecord = function (Id, model, pagename, formId) {
        model.Process = 100;
        model.OperateTime = $("#datetime").val();
        $scope.DataLoading = true;
        Upload.upload({
            method: 'POST',
            url: '../HiddenTrouble/AddRectificationRecord',
            data: { 'SolutionId': Id, 'model': model, "FileList": $scope.FileList }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    mui.toast(ret.Msg);
                    setTimeout(function () {
                        location.href = pagename + "?FormId=" + formId;
                    }, 3000);
                } else
                    mui.toast(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })
    }


    $scope.AddReviewRecord = function (formid, result, model) {
        //var files = document.getElementById("ImageFile").files;
        model.IsComplete = result;
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../HiddenTrouble/AddReviewRecord',
            data: { 'FormId': formid, 'model': model, "FileList": $scope.FileList }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    mui.toast(ret.Msg);
                    setTimeout(function () {
                        location.href = "MHiddenTroubleRectification";
                    }, 3000);
                } else
                    mui.toast(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                mui.toast("请检查网络");
            })
    }

    $scope.ChangeProcess = function (v, solution) {
        if (v == "true") {
            $scope.AddModel.Process = 100;
        } else {
            $scope.AddModel.Process = solution.Process;
        }
        $("#slider-range-min-amount").text($scope.AddModel.Process + "%");
        $("#slider-range-min").slider({
            range: "min",
            value: $scope.AddModel.Process,
            min: 0,
            max: 100,
            slide: function (event, ui) {
                $("#slider-range-min-amount").text(ui.value + "%");
                $scope.AddModel.Process = ui.value;
                if (ui.value == 100) {
                    v = "true";
                }
                else {
                    v = "false";
                }
            }
        });
    }




    $scope.GetDepartmentView = function (year) {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetDepartmentView',
            data: { 'Year': year }
        }).success(function (ret) {
            if (ret.Code == 100) {
                var datalist = ret.Data;
                var deparray = [];
                var total = [];
                var rect = [];
                var overdue = [];
                for (var i = 0; i < datalist.length; i++) {
                    deparray.push(datalist[i].Department);
                    total.push(datalist[i].All);
                    rect.push(datalist[i].Rectification);
                    overdue.push(datalist[i].Overdue);
                }

                var myChart = echarts.init(document.getElementById('countview'));
                var option = {
                    legend: {},
                    tooltip: {},
                    toolbox: {
                        show: true,
                        orient: 'vertical',
                        left: 'right',
                        top: 'center',
                        feature: {
                            mark: { show: true },
                            magicType: { show: true, type: ['line', 'bar', 'stack'] },
                            restore: { show: true },
                            saveAsImage: { show: true }
                        }
                    },
                    xAxis: {
                        type: 'category',
                        data: deparray,
                        splitLine: {
                            show: true,
                            lineStyle: {
                                color: 'rgba(0, 0, 0, 0.06)',
                                width: 1
                            }
                        },
                        axisLine: {
                            lineStyle: {
                                color: 'rgba(0, 0, 0, 0.06)',
                                width: 1,
                            }
                        },
                        axisLabel: {
                            show: true,
                            textStyle: {
                                color: 'rgba(122, 144, 154)'   //这里用参数代替了
                            }
                        }

                    },
                    yAxis: {

                        splitLine: {
                            show: true,
                            lineStyle: {
                                color: 'rgba(0, 0, 0, 0.06)',
                                width: 1
                            }
                        }
                    },
                    grid:
                    {
                        bottom: 20,
                        top: 20,
                        left: 30,
                        right: 25
                    },

                    series: [
                        {
                            name: '总数',
                            type: 'bar',
                            itemStyle: {
                                color: 'rgba(135, 153, 154, 0.7)',
                                borderWidth: 2,
                                borderColor: "rgba(135, 153, 154)",
                            },
                            data: total//[43, 52, 65, 53, 55, 27, 44, 62, 42, 54, 59]
                        },
                        {
                            name: '整改中',
                            type: 'bar',
                            itemStyle: {
                                color: 'rgba(168, 228, 223, 0.6)',
                                borderWidth: 2,
                                borderColor: "rgba(168, 228, 223)",

                            },
                            data: rect// [5, 3, 11, 17, 8, 4, 15, 7, 9, 11, 5]
                        },
                        {
                            name: '过期',
                            type: 'bar',
                            itemStyle: {
                                color: 'rgba(250, 219, 216, 0.6)',
                                borderWidth: 2,
                                borderColor: "rgba(250, 219, 216)",
                            },
                            data: overdue//[1, 0, 3, 2, 1, 5, 2, 0, 4, 5, 4]
                        }
                    ]
                };
                myChart.setOption(option, true);
            } else {
                $scope.DataLoading = false;
                alertify.alert(ret.Msg);
            }

        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetMonthView = function (year, id, SourceType) {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetMonthView',
            data: { 'Year': year, 'SourceType': SourceType }
        }).success(function (ret) {
            if (ret.Code == 100) {
                var datalist = ret.Data;
                var namearray = [];
                var total = [];
                for (var i = 0; i < datalist.length; i++) {
                    namearray.push(datalist[i].Month + "月");
                    total.push(datalist[i].Times);
                }
                var myChart = echarts.init(document.getElementById(id));

                var option = {
                    legend: {},
                    tooltip: {},
                    toolbox: {
                        show: true,
                        orient: 'vertical',
                        left: 'right',
                        top: 'center',
                        feature: {
                            mark: { show: true },
                            magicType: { show: true, type: ['line', 'bar', 'stack'] },
                            restore: { show: true },
                            saveAsImage: { show: true }
                        }
                    },
                    xAxis: {
                        type: 'category',
                        data: namearray,
                        splitLine: {
                            show: true,
                            lineStyle: {
                                color: 'rgba(0, 0, 0, 0.06)',
                                width: 1
                            }
                        },
                        axisLine: {
                            lineStyle: {
                                color: 'rgba(0, 0, 0, 0.06)',
                                width: 1,
                            }
                        },
                        axisLabel: {
                            show: true,
                            textStyle: {
                                color: 'rgba(122, 144, 154)'   //这里用参数代替了
                            }
                        }

                    },
                    yAxis: {

                        splitLine: {
                            show: true,
                            lineStyle: {
                                color: 'rgba(0, 0, 0, 0.06)',
                                width: 1
                            }
                        }
                    },
                    grid:
                    {
                        bottom: 20,
                        top: 20,
                        left: 30,
                        right: 25
                    },

                    series: [
                        {
                            name: '总数',
                            type: 'bar',
                            itemStyle: {
                                color: 'rgba(135, 153, 154, 0.7)',
                                borderWidth: 2,
                                borderColor: "rgba(135, 153, 154)",
                            },
                            data: total
                        }
                    ]
                };
                myChart.setOption(option, true);
            } else {
                $scope.DataLoading = false;
                alertify.alert(ret.Msg);
            }

        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetTypeView = function (year, source) {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetTypeView',
            data: { "Year": year, 'SourceType': source }
        }).success(function (ret) {
            if (ret.Code == 100) {
                var datalist = ret.Data;

                var myChart = echarts.init(document.getElementById('typeview'));
                var option = {
                    title: {
                        show: false,
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '隐患类型分布',
                            type: 'pie',
                            center: ['60%', '50%'],
                            radius: '50%',
                            data: datalist,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);
            } else {
                $scope.DataLoading = false;
                alertify.alert(ret.Msg);
            }

        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetFactoryView = function (year, source) {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetFactoryView',
            data: { "Year": year, "SourceType": source }
        }).success(function (ret) {
            if (ret.Code == 100) {
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('factoryview'));

                var option = {
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '园区分布图',
                            type: 'pie',
                            radius: ['40%', '70%'],
                            avoidLabelOverlap: false,
                            label: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                label: {
                                    show: true,
                                    fontSize: '40',
                                    fontWeight: 'bold'
                                }
                            },
                            labelLine: {
                                show: false
                            },
                            color: ['rgb(83,148,201)', 'rgb(55,191,141)'],
                            data: datalist
                        }
                    ]
                };
                myChart.setOption(option);
            } else {
                $scope.DataLoading = false;
                alertify.alert(ret.Msg);
            }

        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetSourceView = function (year, source) {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetSourceView',
            data: { "Year": year, "SourceType": source }
        }).success(function (ret) {
            if (ret.Code == 100) {
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('souceview'));
                var option = {
                    title: {
                        show: false,
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        top: '5%',
                        left: 'center'
                    },
                    series: [
                        {
                            name: '隐患来源分布',
                            type: 'pie',
                            center: ['50%', '70%'],
                            radius: '50%',
                            data: datalist,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);
            } else {
                $scope.DataLoading = false;
                alertify.alert(ret.Msg);
            }

        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.InitImgeUpload = function (category) {
        setTimeout(function () {
            for (var i = 0; i < $scope.ImageCount.length; i++) {
                var imagebox = "#imagebox_" + $scope.ImageCount[i];
                var dragImgUpload = new DragImgUpload(imagebox, {
                    callback: function (files) {
                        //回调函数，可以传递给后台等等
                        var file = files[0];
                        Upload.upload({
                            method: 'POST',
                            url: '../HiddenTrouble/UploadFormImage',
                            data: { "Category": category },
                            file: file
                        })
                            .success(function (ret) {
                                $scope.Submiting = false;
                                if (ret.Code == 100) {
                                    $scope.FileList.push(ret.Data);

                                } else
                                    alertify.alert(ret.Msg);
                            })
                            .error(function (data, status, headers, config) {
                                common.error($scope);
                                mui.toast("请检查网络");
                            })
                    }
                }, "", $scope.ImageCount[i]);
            }
        }, 2000);
    }

    $scope.InitDatePicker = function (control) {
        (function ($) {
            $.init();
            var btns = $(control);
            btns.each(function (i, btn) {
                btn.addEventListener('tap', function () {
                    var _self = this;
                    if (_self.picker) {
                        _self.picker.show(function (rs) {
                            jQuery(control).val(rs.text);
                            _self.picker.dispose();
                            _self.picker = null;
                        });
                    } else {
                        var optionsJson = this.getAttribute('data-options') || '{}';
                        var options = JSON.parse(optionsJson);
                        var id = this.getAttribute('id');
                        _self.picker = new $.DtPicker(options);
                        _self.picker.show(function (rs) {
                            jQuery(control).val(rs.text);
                            console.log($scope.AddModel);
                            _self.picker.dispose();
                            _self.picker = null;
                        });
                    }
                }, false);
            });
        })(mui);
    }

    $scope.InitUpload = function () {


    }


    $scope.GetSolutionList = function () {
        $scope.SolutionList = [];
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetSolutionList',
            data: { "FormId": $scope.FormId }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.PageLoading = false;
                mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                if (ret.Code == 100) {
                    $scope.SolutionList = ret.Data;
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.InitSolutionListPage = function (id) {
        mui.init({
            pullRefresh: {
                container: '#pullrefresh',
                down: {
                    callback: $scope.GetSolutionList
                }
            }
        });
    }

    $scope.GetEquTypeList = function () {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetEquType'
        }).success(function (ret) {
            if (ret.Code == 100) {
                $scope.EquTypeList = ret.Data;
            } else {
                alertify.alert(ret.Msg);
            }

        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })

    }
    $scope.GetMaintanceDep = function (id, model) {
        if (id == '' || id == '0') {
            model.DepartmentId = '';
        }
        else {
            for (var i = 0; i < $scope.EquTypeList.length; i++) {
                if ($scope.EquTypeList[i].Id == id) {
                    if ($scope.EquTypeList[i].DepartmentId == 0) {
                        model.DepartmentId = $scope.User.DepartmentId + '';
                    }
                    else {
                        model.DepartmentId = $scope.EquTypeList[i].DepartmentId + '';
                    }

                }
            }
        }
    }

    $scope.GetDepartmentList = function (parent, control) {
        $scope.PageLoading = true;
        $scope.DepartmentList = [];
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetDepartmentList'
        }).success(function (ret) {
            $scope.PageLoading = false;
            if (ret.Code == 100) {
                $scope.DepartmentList = ret.Data;
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }
});




app.filter('HideCardNo', function () { //可以注入依赖
    return function (text) {
        if (text != null && text != "")
            return text.replace(/^(.{3})(?:\d+)(.{4})$/, "$1******$2");
    }
});
app.filter('HideLongText', function () { //可以注入依赖
    return function (text) {
        if ((text != null || text != "") && text.length > 10) {
            return text.substr(0, 10) + "..."
        }
        else {
            return text;
        }
    }
});

app.filter('GetFlowStatus', function () { //可以注入依赖
    return function (text) {
        if (text == '0')
            return "已删除";
        else if (text == '1')
            return "编辑中";
        else if (text == '2')
            return "部门审批";
        else if (text == '3')
            return "单位审批";
        else if (text == '4')
            return "总部审核";
        else if (text == '5')
            return "已转发分管";
    }
});
app.filter('GetReviewState', function () { //可以注入依赖
    return function (result) {
        if (result == true)
            return "整改完成";
        else
            return "整改完成";

    }
});

app.filter('GetFlowStatus', function () { //可以注入依赖
    return function (text) {
        if (text == '1')
            return "编辑中";
        else if (text == '2')
            return "待部门审批";
        else if (text == '3')
            return "待单位审批";
        else if (text == '4')
            return "待总部审核";
        else if (text == '5')
            return "审核完成";
    }
});


app.filter('GetWeekDay', function () {
    return function (enddate) {
        var endDate = new Date(enddate);
        var beginDate = new Date(endDate.getFullYear(), 0, 1);
        //星期从0-6,0代表星期天，6代表星期六
        var endWeek = endDate.getDay();
        if (endWeek == 0) endWeek = 7;
        var beginWeek = beginDate.getDay();
        if (beginWeek == 0) beginWeek = 7;
        //计算两个日期的天数差
        var millisDiff = endDate.getTime() - beginDate.getTime();
        var dayDiff = Math.floor((millisDiff + (beginWeek - endWeek) * (24 * 60 * 60 * 1000)) / 86400000);
        return Math.ceil(dayDiff / 7) + 1;
    }

});